home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OTStreamLogViewer / Read Me — OTStreamLogViewer < prev    next >
Encoding:
Text File  |  2000-09-28  |  10.1 KB  |  136 lines  |  [TEXT/ttxt]

  1. Read Me About OTStreamLogViewer
  2.  
  3. 1.0b2
  4.  
  5. OTStreamLogViewer is both a sample and a developer tool.  As a sample, it shows how to use the OT raw streams API to communication with modules in the OT kernel. As a tool, it allows you to view the output of the STREAMS logging facility (strlog).  This is extremely helpful when developing OT kernel plug-ins: modules drivers, and port scanners.
  6.  
  7. About STREAMS Logging
  8.  
  9. The STREAMS architecture defines a standard logging facility in the form of the strlog routine.  This function is described in detail later, but for the moment it is suffice to say that strlog allows kernel code to create a log entry (in which the most important data is a text message) that is passed to the "log" device. A client-side process can connect to this device (by opening a raw stream) and receive these log entries as STREAMS messages.
  10.  
  11. Typically, on a UNIX STREAMS system, there is a client-side process that connects to the log device and writes these log messages to a system administration file. Under Open Transport, no such process is provided, although the entire logging infrastructure is present. OTStreamLogViewer performs the function of the client-side logging process with a cutesy Mac OS user interface.
  12.  
  13. The log events created by the strlog function are aimed at two audiences. Error events are typically an indication of some failure within the network protocol stack and are meant to be read by system adminstrators. Trace events are typically used for "writing to stdout" debugging by the authors of STREAMS protocol modules. OTStreamLogViewer allows you to selectively see either or both types of events. 
  14.  
  15. The strlog Function
  16.  
  17. The prototype for strlog is defined in "strlog.h", one of the low-level interface files that comes with the Open Transport SDK.
  18.  
  19.   extern int_t strlog(int_t mid, int_t sid, int_t level, 
  20.                       uint_t flags, char* fmt, ...);
  21.  
  22. The function result is not meaningful.  The mid parameter is typically your module’s module ID number, as defined by you in the mi_idnum filed of module_info record referenced by your streamtab.  The sid parameter is typically the minor device number of a stream connected to your module. The level parameter specifies the importance of the log message, as defined by the following constants (defined in "OpenTptModule.h"):
  23.  
  24.   enum
  25.   {
  26.       kOTLvlFatal             = 0,
  27.       kOTLvlNonfatal          = 1,
  28.       kOTLvlExtFatal          = 2,
  29.       kOTLvlExtNonfatal       = 3,
  30.       kOTLvlUserErr           = 4,
  31.       kOTLvlInfoErr           = 5,
  32.       kOTLvlInfoOnly          = 6
  33.   };
  34.  
  35. Note: These three parameters are uninterpreted by strlog, except insofar as it matches the parameters against the filter specified by the trace logging client. Specifically you can pass any value you want for mid and sid; they do not have to be valid module ID or stream minor number. In fact, you don’t even have to be developing a module to use strlog. You can call strlog from any kernel code.
  36.  
  37. The flags parameter specifies the type of log event to be created. The following bit masks are defined in "strlog.h":
  38.  
  39.   #define SL_ERROR    0x4     /* Pass message to error logger */
  40.   #define SL_TRACE    0x8     /* Pass message to tracer */
  41.   #define SL_CONSOLE  0x10    /* Print the message on the console */
  42.   #define SL_FATAL    0x1     /* Fatal error */
  43.   #define SL_NOTIFY   0x2     /* Notify the system administrator */
  44.   #define SL_WARN     0x20    /* Warning */
  45.   #define SL_NOTE     0x40    /* Notice this message */
  46.  
  47. You can specify any combination of these flags by ORing the masks together. strlog ignores the flags except for SL_TRACE and SL_ERROR. These flags control whether the log event is sent to either the trace logger (typically used for debugging) or the error logger (typically used for system admin messages). In addition, the SL_CONSOLE flag allows you to specify that the message should be printed on the system console, but this has no effect under Open Transport.
  48.  
  49. Finally, the fmt (and any remaining parameters) are used in a printf-like fashion to form the message string associated with this log. The following format specifiers are permitted: %c, %d, %m (memory, in hex), %o, %x, %s, %u.
  50.  
  51. Open Transport also defines a logging macro, STRLOG, which acts like a function with the following prototype:
  52.  
  53.   STRLOG(queue_t *q, int_t lvl, uint_t flags, char *str)
  54.  
  55. This macros is a convenience function for use specifically by modules. The macro extracts the module ID and stream ID from the supplied queue_t parameter.
  56.  
  57. Reading Log Events
  58.  
  59. The client-side interface to the "log" device is defined in "strlog.h". Rather than describe this in detail, I will refer you to the comments in "LogEngine.h" and "LogEngine.c". These files represent a standalone library which you can use to implement a STREAMS logging facility under Open Transport.
  60.  
  61. Packing List
  62.  
  63. The sample includes the following items:
  64.  
  65. • Read Me — OTStreamLogViewer — This document.
  66.  
  67. • OTStreamLogViewer.µ — A CodeWarrior project to build the OTStreamLogViewer.
  68. • OTStreamLogViewer — A compiled version of the above.
  69.  
  70. • OTStreamLogViewer.rsrc — Resources for the above.
  71. • StreamLogResources.h — C constants for all the resource IDs.
  72.  
  73. • OTStreamLogViewer.c — The bulk of the application code, including the main function. 
  74. • FileLogging.h, FileLogging.c — The code that implements logging to a file. 
  75. • LogEngine — A folder containing the log engine, a library that can be extracted from this program to provide client-side logging support in any application.
  76. • IC Libraries — A bunch of source files, extracted from the Internet Config source, that provide generally useful extensions to the Mac OS toolbox.  See the Read Me inside the folder for more information.
  77. • Internet Config APIs — A minimal set of interfaces and libraries, extracted from the IC 2.0 SDK, that allow OTStreamLogViewer to store its state in the Internet Config preferences database. See the Read Me inside the folder for more information.
  78.  
  79. Building the Sample
  80.  
  81. To build the sample you will need:
  82.  
  83. • CodeWarrior Pro 2, with C and Pascal compilers installed.
  84.  
  85. • The Open Transport SDK. I used version 1.3 of the SDK, but newer and old versions (back to 1.1.1) should work OK.
  86.  
  87. • The ASLM 2.0 SDK, available on the Mac OS SDK CDs.
  88.  
  89. To build the sample, the first thing you have to do is grab all the OT interface files from the OT SDK and put them in one folder. The interfaces that come with CodeWarrior don’t include all the low-level APIs that you will need.  Similarly, you should group all the OT libraries in the same folder. Then modify the access paths for the project to point those folders.
  90.  
  91. Next you should modify the access paths for the project to point to the ASLM developer tools folder.
  92.  
  93. The next step is to open the “OTStreamLogViewer.µ” project file, select the FAT target, and make the project. This results in a fat version of the application.
  94.  
  95. Coding Notes
  96.  
  97. There are three interesting points in the sample code:
  98.  
  99. • The OTStreamLogViewer application contains a lot of user interface code. Writing user interface code under Mac OS is much easier if you have a library of existing functions to wrap around the Mac OS to provide extra functionality. In this sample I use a library of code extract from the Internet Config source code. [Internet Config is in the public domain, so there’s no intellectual property problems with using it’s source.] The library code is actually written in Pascal, with C header files that allow you to call the Pascal code from C source.
  100.  
  101. • This sample demonstrates the use of a raw stream in asynchronous mode. The notifier in "LogEngine.c" shows how to efficiently raw STREAMS messages from the raw stream.
  102.  
  103. • This sample uses the OT memory allocation routines (OTAllocMem and OTFreeMem) for allocating buffers to store log entries in the above notifier (ie at 'interrupt time').  The OT memory allocation routines have a number of important attributes that you should be aware of. There’s a long discussion of this in "OTStreamLogViewer.c".
  104.  
  105. • The OT raw streams API is not available to emulated clients running on PowerPC-based computers. For this reason the application should always be compiled fat.
  106.  
  107. • The 68K version was a real pain to build. Firstly, you have to set CodeWarrior to use 4 byte integers, because the ASLM header files (specifically InitLibraryManager) assume 4 byte integers.  *sigh*  Secondly, you have to make sure that “LibraryManager.o” is linked last, ie comes last in the Segments tab in the project window. If you don’t do this, some ANSI C stuff in “LibraryManager.o” will override the standard stuff in the MSL library and bad things will result.
  108.  
  109. Using OTStreamLogViewer
  110.  
  111. Alas, user documentation has been deferred to a future release.  Some hints and tips:
  112.  
  113. • Never attempt to run the 68K version on a PPC. See DTS Q&A NW 48 for details why not:
  114.  
  115.   <http://devworld.apple.com/dev/qa/nw/nw48.html>
  116.  
  117. • If you want the PowerPC version to remember window positions, install Internet Config Extension 2.0 or later. For the 68K version, any version of Internet Config should suffice.
  118.  
  119. • If your kernel code calls strlog in a very bursty fashion, you may want to increase the partition size of the application. The application accepts log entries at interrupt time but can’t process them until SystemTask time. If it receives a large number (say 2000) log entries at interrupt time before it gets SystemTask time, the application will start dropping log entries.
  120.  
  121. • If you turn on file logging, OTStreamLogViewer will log to a text file call “OTStreamLogViewer Log” in the root of the boot volume. Yes, I know it’s lame user interface (–:
  122.  
  123. Credits and Version History
  124.  
  125. OTStreamLogViewer was written by Quinn “The Eskimo!” as Apple Developer Technical Support sample code.  If you find any problems with this sample, mail <DTS@apple.com> with “Attn: Quinn” as the first line of your mail and I’ll try to fix them up.
  126.  
  127. Version 1.0b1 (Mar 1998) is the first release version.
  128.  
  129. Version 1.0b2 (Jul 1998) fixes a slight memory leak. Important safety tip: always remove a notifier from a raw stream before closing the stream. Updated to CodeWarrior Pro 2.  Updated to IC 2.0 final stuff.
  130.  
  131. Quinn “The Eskimo!”
  132. Apple Developer Technical Support
  133. Networking, Communcations, Hardware
  134.  
  135. 6 Jul 1998
  136.